diff --git a/assets/src/bundles/add_forge/create-request.js b/assets/src/bundles/add_forge/create-request.js
--- a/assets/src/bundles/add_forge/create-request.js
+++ b/assets/src/bundles/add_forge/create-request.js
@@ -6,7 +6,7 @@
*/
import {handleFetchError, errorMessageFromResponse, csrfPost,
- getHumanReadableDate} from 'utils/functions';
+ getHumanReadableDate, genLink} from 'utils/functions';
import userRequestsFilterCheckboxFn from 'utils/requests-filter-checkbox.ejs';
import {swhSpinnerSrc} from 'utils/constants';
@@ -107,16 +107,9 @@
{
data: 'forge_url',
name: 'forge_url',
- render: function(data, type, row) {
- if (type === 'display') {
- let html = '';
- const sanitizedURL = $.fn.dataTable.render.text().display(data);
- html += sanitizedURL;
- html += ` ` +
- '';
- return html;
- }
- return data;
+ render: (data, type, row) => {
+ const sanitizedURL = $.fn.dataTable.render.text().display(data);
+ return genLink(sanitizedURL, type, true);
}
},
{
diff --git a/assets/src/bundles/add_forge/moderation-dashboard.js b/assets/src/bundles/add_forge/moderation-dashboard.js
--- a/assets/src/bundles/add_forge/moderation-dashboard.js
+++ b/assets/src/bundles/add_forge/moderation-dashboard.js
@@ -5,7 +5,7 @@
* See top-level LICENSE file for more information
*/
-import {getHumanReadableDate} from 'utils/functions';
+import {getHumanReadableDate, genLink} from 'utils/functions';
export function onModerationPageLoad() {
populateModerationList();
@@ -48,7 +48,10 @@
{
data: 'forge_url',
name: 'forge_url',
- render: $.fn.dataTable.render.text()
+ render: (data, type, row) => {
+ const sanitizedURL = $.fn.dataTable.render.text().display(data);
+ return genLink(sanitizedURL, type, true);
+ }
},
{
data: 'last_moderator',
diff --git a/assets/src/bundles/admin/deposit.js b/assets/src/bundles/admin/deposit.js
--- a/assets/src/bundles/admin/deposit.js
+++ b/assets/src/bundles/admin/deposit.js
@@ -5,7 +5,7 @@
* See top-level LICENSE file for more information
*/
-import {getHumanReadableDate} from 'utils/functions';
+import {getHumanReadableDate, genLink} from 'utils/functions';
function genSwhLink(data, type, linkText = '') {
if (type === 'display' && data && data.startsWith('swh')) {
@@ -19,21 +19,6 @@
return data;
}
-function genLink(data, type, openInNewTab = false, linkText = '') {
- if (type === 'display' && data) {
- const sData = encodeURI(data);
- if (!linkText) {
- linkText = sData;
- }
- let attrs = '';
- if (openInNewTab) {
- attrs = 'target="_blank" rel="noopener noreferrer"';
- }
- return `${linkText}`;
- }
- return data;
-}
-
export function initDepositAdmin(username, isStaff) {
let depositsTable;
$(document).ready(() => {
diff --git a/assets/src/utils/functions.js b/assets/src/utils/functions.js
--- a/assets/src/utils/functions.js
+++ b/assets/src/utils/functions.js
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2018-2020 The Software Heritage developers
+ * Copyright (C) 2018-2022 The Software Heritage developers
* See the AUTHORS file at the top-level directory of this distribution
* License: GNU Affero General Public License version 3, or any later version
* See top-level LICENSE file for more information
@@ -166,3 +166,19 @@
const date = new Date(data);
return date.toLocaleString();
}
+
+export function genLink(sanitizedUrl, type, openInNewTab = false, linkText = '') {
+ // Display link. It's up to the caller to sanitize sanitizedUrl first.
+ if (type === 'display' && sanitizedUrl) {
+ const encodedSanitizedUrl = encodeURI(sanitizedUrl);
+ if (!linkText) {
+ linkText = encodedSanitizedUrl;
+ }
+ let attrs = '';
+ if (openInNewTab) {
+ attrs = 'target="_blank" rel="noopener noreferrer"';
+ }
+ return `${linkText}`;
+ }
+ return sanitizedUrl;
+}